﻿Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics

'''' <summary>
'''' XNA does not offer a structure that can contain a position, 
'''' a color and a normal so we create one of our own. 
'''' Similar to the XNA structure VertexPositionColor but with a 
'''' normal as well.
'''' </summary>
'Public Structure VertexPositionNormalColor
'    Public Position As Vector3
'    Public Color As Color
'    Public Normal As Vector3
'    Public Shared SizeInBytes As Integer = 7 * 4
'    Public Shared VertexElements As VertexElement() = _
'        New VertexElement() { _
'            New VertexElement(0, 0, VertexElementFormat.Vector3, _
'            VertexElementMethod.[Default], VertexElementUsage.Position, 0), _
'            New VertexElement(0, System.Runtime.InteropServices.Marshal.SizeOf(GetType(Single)) * 3, VertexElementFormat.Color, _
'            VertexElementMethod.[Default], VertexElementUsage.Color, 0), _
'            New VertexElement(0, System.Runtime.InteropServices.Marshal.SizeOf(GetType(Single)) * 4, VertexElementFormat.Vector3, _
'            VertexElementMethod.[Default], VertexElementUsage.Normal, 0) _
'        }
'End Structure

''' <summary>
''' XNA does not offer a structure that can contain a position, 
''' a color and a normal so we create one of our own. 
''' Similar to the XNA structure VertexPositionColor but with a 
''' normal as well.
''' </summary>
<Serializable(), Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
Public Structure VertexPositionNormalColor
    Implements IVertexType
    Public Position As Vector3
    Public Normal As Vector3
    Public Color As Color
    Public Shared ReadOnly VertexDeclaration As VertexDeclaration

    Public Sub New(ByVal position As Vector3, ByVal color As Color)
        Me.Position = position
        Me.Color = color
    End Sub

    Private ReadOnly Property VertexDeclaration1 As VertexDeclaration Implements IVertexType.VertexDeclaration
        Get
            VertexDeclaration1 = VertexPositionNormalColor.VertexDeclaration
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return String.Format("{{Position:{0} Normal:{0} Color:{1}}}", New Object() {Me.Position, Me.Normal, Me.Color})
    End Function

    Public Shared Operator =(ByVal left As VertexPositionNormalColor, ByVal right As VertexPositionNormalColor) As Boolean
        Return ((left.Color = right.Color) AndAlso left.Normal = right.Normal AndAlso (left.Position = right.Position))
    End Operator

    Public Shared Operator <>(ByVal left As VertexPositionNormalColor, ByVal right As VertexPositionNormalColor) As Boolean
        Return Not (left = right)
    End Operator

    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        If (obj Is Nothing) Then
            Return False
        End If
        If (Not obj.GetType Is Me.GetType) Then
            Return False
        End If
        Return (Me = DirectCast(obj, VertexPositionNormalColor))
    End Function

    Shared Sub New()
        Dim elements As VertexElement() = New VertexElement() {New VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), New VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), New VertexElement(24, VertexElementFormat.Color, VertexElementUsage.Color, 0)}
        Dim declaration As New VertexDeclaration(elements)
        declaration.Name = "VertexPositionNormalColor.VertexDeclaration"
        VertexPositionNormalColor.VertexDeclaration = declaration
    End Sub

End Structure